prepare("SELECT classid FROM class ORDER BY classid"); $classStmt->execute(); $classes = $classStmt->fetchAll(PDO::FETCH_ASSOC); $sectionStmt = $DBcon->prepare("SELECT section_name FROM section ORDER BY section_name"); $sectionStmt->execute(); $sections = $sectionStmt->fetchAll(PDO::FETCH_ASSOC); } catch(PDOException $e) { $error = "Error loading data: " . $e->getMessage(); } // If editing, load the subject data if ($subject_id && $_GET['action'] == 'edit') { try { $stmt = $DBcon->prepare("SELECT * FROM subjects WHERE subject_id = ?"); $stmt->execute([$subject_id]); $subject = $stmt->fetch(PDO::FETCH_ASSOC); if (!$subject) { header("Location: subjects.php?message=Subject not found&type=danger"); exit(); } } catch(PDOException $e) { $error = "Error loading subject: " . $e->getMessage(); } } $isEdit = ($_GET['action'] == 'edit'); ?>